// 验证是否登录过
if (get_cookie("key")) {
    $.ajax({
        url: ip + "index.php?s=admincms/login/isadmin",
        type: "post",
        data: {
            "user": get_cookie("user"),
            "key": get_cookie("key")
        },
        success: function (_res) {
            res = JSON.parse(_res);
            if (res.resStatus === 0) {
                // 用户写入页面
                $("#user_name").text(res.data[0].NickName);
                $(".content_left>ul").empty();
               var url=location.href;
               var tiao=true;
             $.each(res.data[0].power_list,function (i,o) {
                 console.log(o);
                    if(url.indexOf(o.url)!==-1){
                        tiao=false;
                    }
                     var _background_=  url.indexOf(o.url)!==-1?'style="background:#000;"':"";

               $(".content_left>ul").append('<a href="'+o.url+'"> <li '+_background_+'><span class="glyphicon '+o.icon+'"></span><p>'+o.names+'</p></li></a>');
             });

             if(tiao){
                 location.href=res.data[0].power_list[0].url;
             }

            }
            if (res.resStatus === 1) {
                location.href = key_address;
            }
        }
    });
} else {
    location.href = key_address;
}

$(function () {
    // 后台对象
    var houtai = {
        linshi_id: "",  //临时id
        linshi_parent_id:'',
        type:"",        //1 一级分类 2.二级分类 3.三级分类
        confirmType:"", //1删除    2上线   3下线
        //防止频繁操作
        old_click_time: 1000,
        click_yes: function () {
            var now_tiem = new Date().getTime();
            if (now_tiem - houtai.old_click_time > 1000) {
                houtai.old_click_time = now_tiem;
                return true;
            } else {
                return false;
            }
        },
        //初始分类
        chushi: function () {
            $.ajax({
                url: ip + "index.php?s=admincms/classify/product",
                type: "post",
                async:false,
                data:{
                    token:get_cookie("key")
                },
                success: function (res) {
                    //写入操作分类table
                    console.log(JSON.parse(res));

                    if (JSON.parse(res).resStatus === 0) {
                        houtai.arr = JSON.parse(res).data;
                        for (var ii = 0, string11 = "<option value=''>全部</option>"; ii < houtai.arr.length; ii++) {
                            string11 += '<option value="' + houtai.arr[ii].pid + '">' + houtai.arr[ii].typesnames + '</option>';
                        }
                        $("#select1").empty().append(string11);
                        $("#select2").empty();
                        houtai.table_string(houtai.arr,1)
                    }
                },
                error:function () {
                    houtai.hint("初始分类请求失败！！");
                }

            });
        },
        //初始主材
        chushi_zhucai:function () {
            $.ajax({
                url: ip + "index.php/admin/cat/showPrincipal",
                type: "post",
                data: {
                },
                success: function (_res) {
                    var res=JSON.parse(_res);
                    if (res.resStatus === 0) {
                        var string='';
                        $.each(res.data,function (i,o) {
                            string+='<option value="'+o.id+'">'+o.title+'</option>'
                        });
                        $('#add_app_pnames').empty().append(string);
                        $('#set_app_pnames').empty().append(string);
                    }else{
                        houtai.hint(res.message);
                    }
                },
                error:function () {
                    houtai.hint("初始主材分类失败！！");
                }
            });
        },
        table_string: function (res,type) {
            // 写入table
            var string_head = "<thead><tr><th>ID</th><th>分类等级</th><th>分类名称</th><th>排序号</th>"+(type===1?'<th>webUrl</th><th>appUrl</th><th>主材名称</th><th>别名</th><th>icon</th><th>背景图</th>':'')+"<th>操作</th></tr></thead>";
            var string_body = "";
            if (res.length>0) {
                $.each(res, function (i, o) {
                    console.log(o)
                    var id;
                    var name;
                    var btn='';
                    var class1_td=''
                    var status=o.state===0?'<button type="button" class="btn btn-default btn-xs down"></span>下线</button> ':'<button type="button" class="btn btn-success btn-xs up"></span> 上线</button> ';
                    switch(type){
                        case 1:
                            id=o.pid;
                            name=o.typesnames;
                            btn='<button type="button" class="btn btn-info btn-xs add2">添加二级分类</button>';
                            class1_td='<td style="vertical-align: middle" class="class_webUrl">'+o.webUrl+'</td><td style="vertical-align: middle" class="class_appUrl">'+o.appUrl+'</td><td style="vertical-align: middle" data-id="'+o.package_id+'" class="class_pname">'+o.pName+'</td><td style="vertical-align: middle" class="class_alias">'+o.alias+'</td><td style="vertical-align: middle;" class="class_icon"><img style="max-width: 100px" src="'+o.icon+'" alt=""></td><td style="vertical-align: middle" class="class_bigImg"><img style="max-width: 100px"  src="'+o.bgImg+'" alt=""></td>';
                        break
                        case 2:
                            id=o.cid;
                            name=o.classnames;
                            btn='<button type="button" class="btn btn-info btn-xs add3">添加三级分类</button>';
                        break
                        case 3:
                            id=o.catId;
                            name=o.catName;
                            status=o.state===1?'<button type="button" class="btn btn-default btn-xs down"></span>下线</button> ':'<button type="button" class="btn btn-success btn-xs up"></span> 上线</button> ';
                        break
                    }
                    string_body +='<tr>' +
                        '<td style="vertical-align: middle" class="class_id">' +id + '</td>' +
                        '<td style="vertical-align: middle"  class="class_type">' + type+ '</td>' +
                        '<td style="vertical-align: middle"  class="class_name">' + name + '</td>' +
                        '<td style="vertical-align: middle"  class="class_sort">' + o.sort + '</td>' +
                        class1_td+
                        '<td style="vertical-align: middle;width: 250px;" class="class_control text-center"> ' +
                        '<button type="button" class="btn btn-warning btn-xs set"><span class="glyphicon glyphicon-tags" aria-hidden="true"></span> 修改</button> ' +
                        '<button type="button" class="btn btn-danger btn-xs remove"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span> 删除</button> ' +
                        status+
                         btn+
                        '</td>' +
                        '</tr>';
                });
            }else{
                string_body = "<tr class='text-center'><td colspan='13'>没有数据</td></tr>";
            }

            $("#up_building_price").empty().append(string_head + string_body);
        },
        //提示功能
        hint:function (str) {
            $(".hint").remove();
            $("body").append("<div class='hint'>"+str+"</div>");
            $(".hint").slideDown(300).delay(2000).slideUp();
        },
        jiancha: function () {
            // 判断是够为空
            for (var i = 0; i < $(".add_goods_body .input_is:visible").length; i++) {
                if ($(".add_goods_body .input_is:visible").eq(i).val() === "") {
                    $(".add_goods_body .input_is:visible").eq(i).focus();
                    houtai.hint("请填写 " + $(".add_goods_body .input_is:visible").eq(i).prev().text());
                    return false;
                }
            }
            return true;
        },
        add:function () {
            if(houtai.linshi_type==0){
                $(".loading").fadeIn(200);
                var form_data = new FormData();
                form_data.append("token",get_cookie('key'));
                form_data.append("oper",0);
                form_data.append("names", $.trim($("#add_class_name").val()));
                form_data.append("sort", $.trim($("#add_class_sort").val()));
                form_data.append("type", $.trim($("#add_look").val()));
                form_data.append("icon", $("#input_file_logo")[0].files[0]);
                form_data.append("bgImg", $("#input_file_bagimg")[0].files[0]);
                form_data.append("appUrl", $.trim($("#add_app_url").val()));
                form_data.append("webUrl", $.trim($("#add_web_url").val()));
                form_data.append("alias", $.trim($("#add_app_alias").val()));
                form_data.append("pid", $.trim($("#add_app_pnames").val()));

                $.ajax({
                    url: ip + "index.php/admin/cat/firstOper",
                    type: "post",
                    data:form_data,
                    success: function (_res) {
                        var res=JSON.parse(_res)
                        if (res.resStatus === 0) {
                            houtai.hint("<span style='color:#0f0'>添加成功</span>");
                            $("#up_building_add").fadeOut();
                            houtai.chushi()
                            $(".loading").fadeOut(200);
                        }else{
                            houtai.hint(res.message);
                            $(".loading").fadeOut(200);
                        }

                    },
                    error:function () {
                        houtai.hint("失败了！！");
                        $(".loading").fadeOut(200);
                    },
                    processData: false,  // 告诉jQuery不要去处理发送的数据
                    contentType: false   // 告诉jQuery不要去设置Content-Type请求头
                });
            }
            if(houtai.linshi_type==1){
                $.ajax({
                    url: ip + "index.php?s=admincms/classify/opto",
                    type: "post",
                    data: {
                        tp: 0,
                        pid: houtai.linshi_id,
                        names:$.trim($('#add_class_name').val()),
                        sort:$.trim($('#add_class_sort').val()),
                        token:get_cookie("key")
                    },
                    success: function (_res) {
                        var res=JSON.parse(_res)
                        if (res.resStatus === 0) {
                            houtai.hint("<span style='color:#0f0'>添加成功</span>");
                            $("#up_building_add").fadeOut();
                            houtai.chushi()
                        }else{
                            houtai.hint(res.message);
                        }
                    },
                    error:function () {
                        houtai.hint("二级分类添加失败了！！");
                    }
                });
            }
            if(houtai.linshi_type==2){
                $.ajax({
                    url: ip + "index.php?s=admincms/Classify/addcats",
                    type: "post",
                    data: {
                        parentId:houtai.linshi_id,
                        catName:$.trim($('#add_class_name').val()),
                        sort:$.trim($('#add_class_sort').val()),
                        token:get_cookie("key")
                    },
                    success: function (_res) {
                        var res=JSON.parse(_res)
                        if (res.resStatus === 0) {
                            houtai.hint("<span style='color:#0f0'>添加成功</span>");
                            $("#up_building_add").fadeOut();
                            houtai.chushi()
                        }else{
                            houtai.hint(res.message);
                        }

                    },
                    error:function () {
                        houtai.hint("三级分类添加失败了！！");
                    }
                });
            }
        },
        set:function () {
            if(houtai.linshi_type==1){
                $(".loading").fadeIn(200);
                var form_data = new FormData();
                form_data.append("id",houtai.linshi_id);
                form_data.append("token",get_cookie('key'));
                form_data.append("oper",2);
                form_data.append("names", $.trim($("#set_class_name").val()));
                form_data.append("sort", $.trim($("#set_class_sort").val()));
                form_data.append("type", $.trim($("#set_look").val()));
                form_data.append("icon", $("#input_file_logo_set")[0].files[0]);
                form_data.append("bgImg", $("#input_file_bagimg_set")[0].files[0]);
                form_data.append("appUrl", $.trim($("#set_app_url").val()));
                form_data.append("webUrl", $.trim($("#set_web_url").val()));
                form_data.append("alias", $.trim($("#set_app_alias").val()));
                form_data.append("pid", $.trim($("#set_app_pnames").val()));

                $.ajax({
                    url: ip + "index.php/admin/cat/firstOper",
                    type: "post",
                    data:form_data,
                    success: function (_res) {
                        var res=JSON.parse(_res)
                        if (res.resStatus === 0) {
                            houtai.hint("<span style='color:#0f0'>修改成功</span>");
                            $("#up_building_set").fadeOut();
                            houtai.chushi()
                            $(".loading").fadeOut(200);
                        }else{
                            houtai.hint(res.message);
                            $(".loading").fadeOut(200);
                        }

                    },
                    error:function () {
                        houtai.hint("二级分类修改失败了！！");
                        $(".loading").fadeOut(200);
                    },
                    processData: false,  // 告诉jQuery不要去处理发送的数据
                    contentType: false   // 告诉jQuery不要去设置Content-Type请求头
                });
            }
            if(houtai.linshi_type==2){
                $.ajax({
                    url: ip + "index.php?s=admincms/classify/opto",
                    type: "post",
                    data: {
                        tp: 2,
                        id: houtai.linshi_id,
                        pid: houtai.linshi_parent_id,
                        names:$.trim($('#set_class_name').val()),
                        sort:$.trim($('#set_class_sort').val()),
                        token:get_cookie("key")
                    },
                    success: function (_res) {
                        var res=JSON.parse(_res)
                        if (res.resStatus === 0) {
                            houtai.hint("<span style='color:#0f0'>修改成功</span>");
                            $("#up_building_set").fadeOut();
                            houtai.chushi()
                        }else{
                            houtai.hint(res.message);
                        }

                    },
                    error:function () {
                        houtai.hint("二级分类修改失败了！！");
                    }
                });
            }
            if(houtai.linshi_type==3){
                $.ajax({
                    url: ip + "index.php?s=admincms/Classify/editcats",
                    type: "post",
                    data: {
                        catId:houtai.linshi_id,
                        parentId:houtai.linshi_parent_id,
                        catName:$.trim($('#set_class_name').val()),
                        sort:$.trim($('#set_class_sort').val()),
                        token:get_cookie("key")
                    },
                    success: function (_res) {
                        var res=JSON.parse(_res)
                        if (res.resStatus === 0) {
                            houtai.hint("<span style='color:#0f0'>修改成功</span>");
                            $("#up_building_set").fadeOut();
                            houtai.chushi()
                        }else{
                            houtai.hint(res.message);
                        }

                    },
                    error:function () {
                        houtai.hint("三级分类修改失败了！！");
                    }
                });
            }
        },
        remove:function () {
            if(houtai.linshi_type==1){
                $.ajax({
                    url: ip + "index.php/admin/cat/firstOper",
                    type: "post",
                    data: {
                        id:houtai.linshi_id,
                        oper:1,
                        token:get_cookie("key")
                    },
                    success: function (_res) {
                        var res=JSON.parse(_res)
                        if (res.resStatus === 0) {
                            houtai.hint("<span style='color:#0f0'>删除成功</span>");
                            $("#modal_wrap").fadeOut();
                            houtai.chushi()
                        }else{
                            houtai.hint(res.message);
                        }

                    },
                    error:function () {
                        houtai.hint("二级分类修改失败了！！");
                    }
                });
            }
            if(houtai.linshi_type==2){
                $.ajax({
                    url: ip + "index.php?s=admincms/classify/opto",
                    type: "post",
                    data: {
                        tp: 1,
                        pid: houtai.linshi_parent_id,
                        id: houtai.linshi_id,
                        token:get_cookie("key")
                    },
                    success: function (_res) {
                        var res=JSON.parse(_res)
                        if (res.resStatus === 0) {
                            houtai.hint("<span style='color:#0f0'>删除成功</span>");
                            $("#modal_wrap").fadeOut();
                            houtai.chushi()
                        }else{
                            houtai.hint(res.message);
                        }

                    },
                    error:function () {
                        houtai.hint("二级分类删除失败了！！");
                    }
                });
            }
            if(houtai.linshi_type==3){
                $.ajax({
                    url: ip + "index.php?s=admincms/Classify/delcats",
                    type: "post",
                    data: {
                        catId:houtai.linshi_id,
                        token:get_cookie("key")
                    },
                    success: function (_res) {
                        var res=JSON.parse(_res)
                        if (res.resStatus === 0) {
                            houtai.hint("<span style='color:#0f0'>删除成功</span>");
                            $("#modal_wrap").fadeOut();
                            houtai.chushi()
                        }else{
                            houtai.hint(res.message);
                        }

                    },
                    error:function () {
                        houtai.hint("三级分类删除失败了！！");
                    }
                });
            }
        },
        up_line:function () {
            if(houtai.linshi_type==1){
                $.ajax({
                    url: ip + "index.php/admin/cat/firstUpDown",
                    type: "post",
                    data: {
                        id:houtai.linshi_id,
                        state:0,
                        token:get_cookie("key")
                    },
                    success: function (_res) {
                        var res=JSON.parse(_res)
                        if (res.resStatus === 0) {
                            houtai.hint("<span style='color:#0f0'>上线成功</span>");
                            $("#modal_wrap").fadeOut();
                            houtai.chushi()
                        }else{
                            houtai.hint(res.message);
                        }

                    },
                    error:function () {
                        houtai.hint("二级分类修改失败了！！");
                    }
                });
            }
            if(houtai.linshi_type==2){
                $.ajax({
                    url: ip + "index.php?s=admincms/Classify/catShow",
                    type: "post",
                    data: {
                        cid:houtai.linshi_id,
                        token:get_cookie("key")
                    },
                    success: function (_res) {
                        var res=JSON.parse(_res)
                        if (res.resStatus === 0) {
                            houtai.hint("<span style='color:#0f0'>上线成功</span>");
                            $("#modal_wrap").fadeOut();
                            houtai.chushi()
                        }else{
                            houtai.hint(res.message);
                        }

                    },
                    error:function () {
                        houtai.hint("二级分类修改失败了！！");
                    }
                });
            }
            if(houtai.linshi_type==3){
                $.ajax({
                    url: ip + "index.php?s=admincms/Classify/catByShow",
                    type: "post",
                    data: {
                        catId:houtai.linshi_id,
                        token:get_cookie("key")
                    },
                    success: function (_res) {
                        var res=JSON.parse(_res)
                        if (res.resStatus === 0) {
                            houtai.hint("<span style='color:#0f0'>上线成功</span>");
                            $("#modal_wrap").fadeOut();
                            houtai.chushi()
                        }else{
                            houtai.hint(res.message);
                        }

                    },
                    error:function () {
                        houtai.hint("三级分类删除失败了！！");
                    }
                });
            }
        },
        down_line:function () {
            if(houtai.linshi_type==1){
                $.ajax({
                    url: ip + "index.php/admin/cat/firstUpDown",
                    type: "post",
                    data: {
                        id:houtai.linshi_id,
                        state:2,
                        token:get_cookie("key")
                    },
                    success: function (_res) {
                        var res=JSON.parse(_res)
                        if (res.resStatus === 0) {
                            houtai.hint("<span style='color:#0f0'>上线成功</span>");
                            $("#modal_wrap").fadeOut();
                            houtai.chushi()
                        }else{
                            houtai.hint(res.message);
                        }

                    },
                    error:function () {
                        houtai.hint("二级分类修改失败了！！");
                    }
                });
            }
            if(houtai.linshi_type==2){
                $.ajax({
                    url: ip + "index.php?s=admincms/Classify/catHide",
                    type: "post",
                    data: {
                        cid:houtai.linshi_id,
                        token:get_cookie("key")
                    },
                    success: function (_res) {
                        var res=JSON.parse(_res)
                        if (res.resStatus === 0) {
                            houtai.hint("<span style='color:#0f0'>上线成功</span>");
                            $("#modal_wrap").fadeOut();
                            houtai.chushi()
                        }else{
                            houtai.hint(res.message);
                        }

                    },
                    error:function () {
                        houtai.hint("二级分类修改失败了！！");
                    }
                });
            }
            if(houtai.linshi_type==3){
                $.ajax({
                    url: ip + "index.php?s=admincms/Classify/catByHide",
                    type: "post",
                    data: {
                        catId:houtai.linshi_id,
                        token:get_cookie("key")
                    },
                    success: function (_res) {
                        var res=JSON.parse(_res)
                        if (res.resStatus === 0) {
                            houtai.hint("<span style='color:#0f0'>上线成功</span>");
                            $("#modal_wrap").fadeOut();
                            houtai.chushi()
                        }else{
                            houtai.hint(res.message);
                        }

                    },
                    error:function () {
                        houtai.hint("二级分类修改失败了！！");
                    }
                });
            }
        },
        huoqu_url: function (file,$el) {
            var form_reader = new FileReader();
            form_reader.onload = function (e) {
                form_reader=null;
                $el.empty().append("<img data-img='"+file.name+"' src='" + e.target.result + "'/>");
                file=null;
            };
            form_reader.readAsDataURL(file);
        },
    };
    // 初始分类
    houtai.chushi();
    houtai.chushi_zhucai()
    // 分类一改变事件
    $("#select1").bind("change", function () {
        houtai.linshi_parent_id=$(this).val()
        for (var b = 0,string2="<option value=''>请选择</option>",string3=""; b < houtai.arr.length; b++) { //循环分类查找对应的子集
            if (houtai.arr[b].pid == $(this).val()) {
                for (var a = 0; a < houtai.arr[b].activity_list.length; a++) {
                    string2 += '<option value="' + houtai.arr[b].activity_list[a].cid + '">' + houtai.arr[b].activity_list[a].classnames + '</option>';
                }
                break;
            }
        }
        $("#select2").empty().append(string2);

        var $that=$(this)
        if($that.val()===''){
            houtai.table_string(houtai.arr,1)
        }else{
            console.log(houtai.arr)
            $.each(houtai.arr,function(i,o){
               if(o.pid==$that.val()){
                   houtai.table_string(o.activity_list,2)
               }
            })
        }
    });
    // 分类二改变事件
    $("#select2").bind("change", function () {
        houtai.linshi_parent_id=$(this).val()
        for (var b = 0,string3=""; b < houtai.arr.length; b++) { //循环分类查找对应的子集
                for (var a = 0; a < houtai.arr[b].activity_list.length; a++) {
                    if (houtai.arr[b].activity_list[a].cid == $(this).val()) {
                        for (var bb = 0; bb < houtai.arr[b].activity_list[a].cats_list.length; bb++) {
                            string3 += '<option value="' + houtai.arr[b].activity_list[a].cats_list[bb].catId + '">' + houtai.arr[b].activity_list[a].cats_list[bb].catName + '</option>';
                        }
                        break;
                    }
                }
        }
        $("#select3").empty().append(string3);
        houtai.table_string([],3)
        var $that=$(this)
            $.each(houtai.arr,function(i,o){
                console.log(1)
                if(o.pid==$('#select1').val()){
                    $.each(o.activity_list,function (i,o) {
                        console.log(o)
                        if($that.val()==o.cid){
                            houtai.table_string(o.cats_list,3)
                            return false
                        }
                    })
                    return false
                }
            })
    });
    // 添加一级分类按钮
    $("#add_up_btn").bind("click",function () {
        houtai.linshi_type=0
        $('.isclass1').show()
         $('#up_building_add').fadeIn()
    });
    // 添加分类确认
    $(".add_confirm").bind("click",function () {
       if(houtai.jiancha()){
           if(houtai.linshi_type==0){
               if($("#input_file_logo")[0].files.length<1){
                   houtai.hint('请点击添加icon图标')
               }else if($("#input_file_bagimg")[0].files.length<1){
                   houtai.hint('请点击添加分类背景图')
               }
           }
          else{
               houtai.add();
           }
       }
    });
    // 修改分类确认
    $(".set_confirm").bind("click",function () {
       if(houtai.jiancha()){
           houtai.set();
       }
    });

    // logo图片上传按钮
    $("#up_logo_button").bind("click", function () {
        $("#input_file_logo").click();
    });
    $("#input_file_logo").bind('change',function () {
        if(this.files.length){
            houtai.huoqu_url(this.files[0],$('.img_wrap_logo '))
        }
    });

    // 分类背景图片上传按钮
    $("#up_bagimg_button").bind("click", function () {
        $("#input_file_bagimg").click();
    });
    $("#input_file_bagimg").bind('change',function () {
        if(this.files.length){
            houtai.huoqu_url(this.files[0],$('.img_wrap_bagimg '))
        }
    });
    // 修改logo图片上传按钮
    $("#up_logo_button_set").bind("click", function () {
        $("#input_file_logo_set").click();
    });
    $("#input_file_logo_set").bind('change',function () {
        if(this.files.length){
            houtai.huoqu_url(this.files[0],$('.img_wrap_logo_set '))
        }
    });

    //修改分类背景图片上传按钮
    $("#up_bagimg_button_set").bind("click", function () {
        $("#input_file_bagimg_set").click();
    });
    $("#input_file_bagimg_set").bind('change',function () {
        if(this.files.length){
            houtai.huoqu_url(this.files[0],$('.img_wrap_bagimg_set '))
        }
    });



    // 修改分类
    $("#up_building_price").on("click",".set",function () {
        houtai.linshi_id=$(this).parents("tr").find(".class_id").text();
        houtai.linshi_type=$(this).parents("tr").find(".class_type").text();
        $("#set_class_name").val($(this).parents("tr").find(".class_name").text());
        $("#set_class_sort").val($(this).parents("tr").find(".class_sort").text());
        if(houtai.linshi_type==='1'){
            $('#input_file_logo_set').val('')
            $("#set_web_url").val($(this).parents("tr").find(".class_webUrl").text());
            $("#set_app_url").val($(this).parents("tr").find(".class_appUrl").text());
            $("#set_app_alias").val($(this).parents("tr").find(".class_alias").text());
            $('#set_app_pnames').val($(this).parents("tr").find(".class_pname").attr('data-id'))
            $(".img_wrap_logo_set").empty().append('<img src="'+$(this).parents("tr").find(".class_icon img").attr('src')+'"/>');
            $(".img_wrap_bagimg_set ").empty().append('<img src="'+$(this).parents("tr").find(".class_bigImg img").attr('src')+'"/>');
            $(".isclass1").show();
        }else{
            $(".isclass1").hide();
        }
       $("#up_building_set").fadeIn();
    });
    // 删除分类
    $("#up_building_price").on("click",".remove",function () {
        houtai.linshi_id=$(this).parents("tr").find(".class_id").text();
        houtai.linshi_type=$(this).parents("tr").find(".class_type").text();
        houtai.confirmType=1;
        $(".modal-body").empty().append("您确定要删除 <span style='color:#f10;'>"+$(this).parents("tr").find(".class_name").text()+"</span> 吗？");
        $("#modal_wrap").show();
    });
    // 上线分类
    $("#up_building_price").on("click",".up",function () {
        houtai.linshi_id=$(this).parents("tr").find(".class_id").text();
        houtai.linshi_type=$(this).parents("tr").find(".class_type").text();
        houtai.confirmType=2;
        $(".modal-body").empty().append("您确定要上线 <span style='color:#f10;'>"+$(this).parents("tr").find(".class_name").text()+"</span> 吗？");
        $("#modal_wrap").show();
    });
    // 下线分类
    $("#up_building_price").on("click",".down",function () {
        houtai.linshi_id=$(this).parents("tr").find(".class_id").text();
        houtai.linshi_type=$(this).parents("tr").find(".class_type").text();
        houtai.confirmType=3;
        $(".modal-body").empty().append("您确定要下线 <span style='color:#f10;'>"+$(this).parents("tr").find(".class_name").text()+"</span> 吗？");
        $("#modal_wrap").show();
    });
    $("#up_building_price").on("click",".add2",function () {
        houtai.linshi_id=$(this).parents("tr").find(".class_id").text();
        houtai.linshi_type=$(this).parents("tr").find(".class_type").text();
        $('.isclass1').hide()
        $('#up_building_add').fadeIn()
    });
    $("#up_building_price").on("click",".add3",function () {
        houtai.linshi_id=$(this).parents("tr").find(".class_id").text();
        houtai.linshi_type=$(this).parents("tr").find(".class_type").text();
        $('.isclass1').hide()
        $('#up_building_add').fadeIn()
    });
    $("#modal_close").bind("click",function () {
        $("#modal_wrap").hide();
    });
    // 收展事件
    $(".right-top>b").bind("click", function () {
        if ($(".content_left").is(":hidden")) {
            $(".content_left").removeClass("ishidden");
            $(".content_right").removeClass("iskuozhang");
        } else {
            $(".content_left").addClass("ishidden");
            $(".content_right").addClass("iskuozhang");
        }
    });
    $("#confirm").bind("click", function () {
        if (houtai.click_yes()) {
            if(houtai.confirmType===1){
                houtai.remove();
            }else if(houtai.confirmType===2){
                houtai.up_line();
            }else if(houtai.confirmType===3){
                houtai.down_line();
            }

        }

    });
    // 修改取消
    $(".cancle_set").bind("click", function () {
        $(".set_shangpin").fadeOut(200);
    });
    //退出按钮
    $("#exit").bind("click", function () {
        set_cookie("key", "", 0);
        location.href = key_address;
    });
    //头像按钮
    $(".right-top>div").bind("click", function (e) {
        $("#exit").slideToggle();
        e.stopPropagation();
    });
    $(window).bind("click", function () {
        $("#exit").slideUp();
    });
});
